import plotly.io as pio
pio.renderers.default = "notebook"
from dwave.system import DWaveSampler, EmbeddingComposite
from schedule import *
import neal
import plotly.express as px
from tabu import TabuSampler
from dwave_qbsolv import QBSolv
from anneal_solver import solvelog_dwave
#Flag damit nicht unbeabsichtigt der quantumcomputer verwendet wird
use_quantum=True
#maximale Zeit
s = Schedule(time_max=6)
# bitte nur benötigte anzahl der maschinen angeben, wir haben keinen preprocessing step um unnötige maschinen heraus zufiltern
s.build_machines(3)
#Jobs
s.create_job({0: (1, 1), 2: (1, 1)})
s.create_job({0: (1, 1), 1: (1, 2)})
s.create_job({1: (1, 2), 2: (1, 1)})
s.create_job({0: (1, 1), 1: (1, 2), 2: (1, 1)})
print(s)
---------------------------- Arbeitsplan Job 0 Operationen: Machine(nr=0, name='m0', parallel_operations=1, start_time=0) Dauer: 1 Anzahl: 1 Machine(nr=2, name='m2', parallel_operations=1, start_time=0) Dauer: 1 Anzahl: 1 Job 1 Operationen: Machine(nr=0, name='m0', parallel_operations=1, start_time=0) Dauer: 1 Anzahl: 1 Machine(nr=1, name='m1', parallel_operations=1, start_time=0) Dauer: 1 Anzahl: 2 Job 2 Operationen: Machine(nr=1, name='m1', parallel_operations=1, start_time=0) Dauer: 1 Anzahl: 2 Machine(nr=2, name='m2', parallel_operations=1, start_time=0) Dauer: 1 Anzahl: 1 Job 3 Operationen: Machine(nr=0, name='m0', parallel_operations=1, start_time=0) Dauer: 1 Anzahl: 1 Machine(nr=1, name='m1', parallel_operations=1, start_time=0) Dauer: 1 Anzahl: 2 Machine(nr=2, name='m2', parallel_operations=1, start_time=0) Dauer: 1 Anzahl: 1 ----------------------------
qubo=Qubo(s)
#start term
qubo.penalty_terms[1]=1
# nur eine maschine/job pro job/maschine gleichzeiting
qubo.penalty_terms[2]=1
qubo.penalty_terms[3]=1
# 4 hat keine bedeutung, war ursprünglich für die deadlines vorgesehen
# da wir diese aber ohne strafterme lösen, ist dieses feld leer
# Just in time
qubo.penalty_terms[5]=0
qubo.calculate_qubo()
print(f"qbits: {len(qubo.h)}")
# qubo berechnung falls mehrere Maschinen oder Jobs gleichzeitig verwendet werden sollten - (dies muss im schedule angegeben werden)
# qubo.calculate_qubo_virtuell()
qbits: 75
qubo.plot_qubo()
qubo.plot_connections_qubo_states()
qubo.plot_qubo_terms()
response = QBSolv().sample_qubo(qubo.J, num_repeats=100)
sol3 = response.samples()[0]
*temp, _ = qubo.interpret_solution_dict(sol3)
print(temp)
qubo.plot_solution()
[[1, 16, 21, 25, 28, 49, 50, 52, 57, 64, 65, 73], [state(j:0,m:0,t:1), state(j:0,m:2,t:3), state(j:1,m:0,t:2), state(j:1,m:1,t:0), state(j:1,m:1,t:3), state(j:2,m:1,t:4), state(j:2,m:1,t:5), state(j:2,m:2,t:1), state(j:3,m:0,t:0), state(j:3,m:1,t:1), state(j:3,m:1,t:2), state(j:3,m:2,t:4)], -18.0, {1: -18, 2: 0, 3: 0, 4: 0, 5: 0.0}, 18]
if use_quantum:
answer = solvelog_dwave(qubo,1000)
*temp2, _ = qubo.interpret_solution_dict(
{x: y for x, y in answer.samples()[0].items()})
print(temp2)
qubo.plot_solution()
[[2, 57, 17, 23, 53, 74, 25, 30, 46, 65, 66, 49], [state(j:0,m:0,t:2), state(j:3,m:0,t:0), state(j:0,m:2,t:4), state(j:1,m:0,t:4), state(j:2,m:2,t:2), state(j:3,m:2,t:5), state(j:1,m:1,t:0), state(j:1,m:1,t:5), state(j:2,m:1,t:1), state(j:3,m:1,t:2), state(j:3,m:1,t:3), state(j:2,m:1,t:4)], -18.0, {1: -18, 2: 0, 3: 0, 4: 0, 5: 0.0}, 18]
df=answer.to_pandas_dataframe()
px.histogram(df,"chain_break_fraction")
px.scatter(df, y="energy", x="chain_break_fraction")
# uncomment to export it as html
#!jupyter nbconvert --to=html example2.ipynb
[NbConvertApp] WARNING | Config option `extra_template_pathss` not recognized by `HTMLExporter`. Did you mean one of: `extra_template_basedirs, extra_template_paths, template_paths`?
Traceback (most recent call last):
File "D:\Anaconda3\Scripts\jupyter-nbconvert-script.py", line 10, in <module>
sys.exit(main())
File "D:\Anaconda3\lib\site-packages\jupyter_core\application.py", line 254, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "D:\Anaconda3\lib\site-packages\traitlets\config\application.py", line 845, in launch_instance
app.start()
File "D:\Anaconda3\lib\site-packages\nbconvert\nbconvertapp.py", line 350, in start
self.convert_notebooks()
File "D:\Anaconda3\lib\site-packages\nbconvert\nbconvertapp.py", line 519, in convert_notebooks
self.exporter = cls(config=self.config)
File "D:\Anaconda3\lib\site-packages\nbconvert\exporters\templateexporter.py", line 325, in __init__
super().__init__(config=config, **kw)
File "D:\Anaconda3\lib\site-packages\nbconvert\exporters\exporter.py", line 114, in __init__
self._init_preprocessors()
File "D:\Anaconda3\lib\site-packages\nbconvert\exporters\templateexporter.py", line 490, in _init_preprocessors
super()._init_preprocessors()
File "D:\Anaconda3\lib\site-packages\nbconvert\exporters\exporter.py", line 266, in _init_preprocessors
self.register_preprocessor(preprocessor, enabled=True)
File "D:\Anaconda3\lib\site-packages\nbconvert\exporters\exporter.py", line 227, in register_preprocessor
preprocessor_cls = import_item(preprocessor)
File "D:\Anaconda3\lib\site-packages\traitlets\utils\importstring.py", line 30, in import_item
module = __import__(package, fromlist=[obj])
ModuleNotFoundError: No module named 'jupyter_contrib_nbextensions'